package com.ppc.mapper.employer;


import com.ppc.entity.Employer;
import com.ppc.entity.Recording;
import com.ppc.entity.Requirement;
import com.ppc.entity.Task;
import com.ppc.entity.UserPPC;
import com.ppc.entity.Worker;
import com.ppc.vo.EmployerDataVO;
import com.ppc.vo.EmployerLoginVO;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


/**
 * 雇主mapper层
 *
 * @author LENOVO
 * @date 2023/12/20
 */
@Mapper
public interface EmployerMapper {


  @Update("update employer set employer_status=3 where user_id=#{userId}")
  void unregisterEmployer(Long userId);

  EmployerLoginVO getEmployerByPhoneOrEmailWithPwd(UserPPC userPPC);

  void insertEmployer(Employer employer);


  void updateImg(Long fileId, Long userId);


  /**
   * 雇主登录
   *
   * @param userPPC
   * @return {@link EmployerLoginVO}
   */
  EmployerLoginVO getEmployerByUsernameAndPwd(UserPPC userPPC);

  /**
   * 获取个人资料
   *
   * @param employerId
   * @return {@link EmployerDataVO}
   */

  EmployerDataVO getData(Long employerId);

  /**
   * 获取密码
   *
   * @param user
   * @return {@link String}
   */
  String getPasswordByPhoneOrEmail(UserPPC user);

  /**
   * 雇主充值
   * @param employerCount
   * @param employerId
   */
  void recharge(Float employerCount, Long employerId);

  /**
   * 获取信誉
   *
   * @param employerId
   * @return int
   */
  int getCredit(Long employerId);


  /**
   * 获取订单
   *
   * @param taskId
   * @return {@link Task}
   */

  @Select("select * from task where task_id = #{taskId}")
  Task getById(Long taskId);

  /**
   * 获取需求
   *
   * @param taskId
   * @return {@link Requirement}
   */
  @Select("select re.* from requirement re LEFT JOIN task ts on re.require_id = ts.require_id " +
      "where task_id = #{taskId}")
  Requirement getRequirementById(Long taskId);


  /**
   * 评论工人
   *
   * @param taskId
   * @param workerRating
   */
  void commentWorker(Long taskId, int workerRating);


  /**
   * 更新工人信誉
   *
   * @param workerId
   * @param workerCredit
   */
  void updateWorkerCredit(Long workerId, int workerCredit);

  /**
   * 获取worker
   *
   * @param taskId
   * @return {@link Worker}
   */
  @Select("select wo.* from task ts LEFT JOIN requirement re on ts.require_id = re.require_id " +
      "LEFT JOIN worker wo on wo.worker_id=ts.worker_id where task_id = #{taskId}")
  Worker getWorkerById(Long taskId);

  /**
   * 获取employerId
   *
   * @param userId
   * @return {@link Long}
   */
  @Select("select employer_id from employer where user_id=#{userId}")
  Long getEmployerIdByUserId(Long userId);


  /**
   * 创建信誉记录
   *
   * @param recording
   */
  void createCreditRecording(Recording recording);

  /**
   * 获取信誉记录
   *
   * @param userId
   * @return {@link List}<{@link String}>
   */
  List<String> getEmployerCreditRecording(Long userId);

  /**
   * 获取余额记录
   *
   * @param userId
   * @return {@link List}<{@link String}>
   */
  List<String> getEmployerCountRecording(Long userId);

  /**
   * 获取余额
   *
   * @param employerId
   * @return int
   */
  Float getCount(Long employerId);

  /**
   * 更改个人信息
   *
   * @param userPPC
   */
  void changeInformationInPPC(UserPPC userPPC);

  @Select("Select count(require_id) from requirement where employer_id=#{employerId} and require_status!=1")
  Integer selectEmployerCount(Long employerId);
}
